import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_global.dart';
import 'package:flutter_learn_vi/src/bean/bean_mine_uestion.dart';
import 'package:flutter_learn_vi/src/common/global.dart';
import 'package:flutter_learn_vi/src/page/home/new/v4_study_item_widget.dart';
import 'package:flutter_learn_vi/src/page/mine/mine_my_exam_page.dart';
import 'package:flutter_learn_vi/src/page/mine/mine_study_recoder_page.dart';
import 'package:flutter_learn_vi/src/page/mine/new/score/mine_my_score_page.dart';
import 'package:flutter_learn_vi/src/page/mine/question_model.dart';
import 'package:flutter_learn_vi/src/page/study/main_exam_page.dart';
import 'package:flutter_learn_vi/src/page/train/tain_main_page.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/5.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class HomeitemStudyV4Widget extends StatefulWidget {
  @override
  _HomeitemStudyWidgetState createState() => _HomeitemStudyWidgetState();
}

class _HomeitemStudyWidgetState extends State<HomeitemStudyV4Widget>
    with MineQuestionModel {
  @override
  void initState() {
    super.initState();
    initData();
  }

  StudyModelBean _studyModelBean;
  List<StudyModelItemBean> _list = [];

  void initData() async {
    _studyModelBean = await getStudyModel();
    if (_studyModelBean != null) {
      rootStreamController.add(GlobalBean(204, true));
    }

    _list = [];
    for (int i = 0; i < 10; i++) {
      if (i < 4) {
        _list.add(_studyModelBean.studyModelItemList[i]);
      } else if (i == 4) {
        _list.add(StudyModelItemBean("更多", MainExamPage(), 1));
      } else if (i == 5) {
        _list.add(_studyModelBean.studyModelItemList[4]);
      } else if (i == 6) {
        _list.add(StudyModelItemBean(
            "积分排行",
            MyScorePage(
              scoreRankType: ScoreRankType.integral,
            ),
            1));
      } else if (i == 7) {
        _list.add(StudyModelItemBean("学习记录", MyStudyRecoderPage(), 1));
      } else if (i == 8) {
        _list.add(StudyModelItemBean("我的考试", MineMyExamPage(), 1));
      } else if (i == 9) {
        _list.add(StudyModelItemBean("我的培训", TrainMainPage(), 1));
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    if (_studyModelBean == null) {
      return Container();
    }
    return Stack(
      alignment: Alignment.center,
      children: [
        Container(
          margin: EdgeInsets.only(left: 12, right: 12, top: 22, bottom: 8),
          height: 164,
          alignment: Alignment.center,
          width: MediaQuery.of(context).size.width,
          child: GridView.builder(
            physics: NeverScrollableScrollPhysics(),
            padding: EdgeInsets.zero,
            //itemCount: _studyModelBean.studyModelItemList.length,
            itemCount: 10,
            itemBuilder: (BuildContext context, int index) {
              StudyModelItemBean itemBean = _list[index];

              return StudyItemV4Widget(
                  itemBean, "assets/images/2.0x/icon_${index + 1}.png", index,
                  pading: 0);
            },
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              //纵轴间距
              mainAxisSpacing: 2.0,
              //横轴间距
              crossAxisSpacing: 2.0,
              //子组件宽高长度比例
              childAspectRatio: 1, crossAxisCount: 5,
            ),
          ),
        )
      ],
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
